package com.z996.spring6;

import com.z996.spring6.pojo.User;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 简述:<br>
 * 实验十：bean 的作用域
 *
 * @Author zfh18
 * @Date 2024-02-02 15:27
 * @Version 1.0
 **/
public class DIActionScopeTest {
    private Logger logger = LoggerFactory.getLogger(DIActionScopeTest.class);


    /**
     * @Description 通过获取两次相同对象 根据地址来判断特性
     * @Author zfh18
     * @Date 15:38 2024-02-02
     **/
    @Test
    public void testByClassAndId() {

        ApplicationContext context = new ClassPathXmlApplicationContext("bean-DI-ActionScope.xml");
        User userSingleton1 = (User) context.getBean("user");
        User userSingleton2 = (User) context.getBean("user");

        logger.info("bean作用域->单例:{} vs {} 结果:{}", userSingleton1.toString(), userSingleton2.toString(), userSingleton1 == userSingleton2);


        User userPrototype1 = (User) context.getBean("user2");
        User userPrototype2 = (User) context.getBean("user2");

        logger.info("bean作用域->多列:{} vs {} 结果:{}", userPrototype1.toString(), userPrototype2.toString(), userPrototype1 == userPrototype2);

    }

}
